/**
 * Created by chenyong on 2015/11/13.
 */
var express = require('express');
var request = require('request');
var router = express.Router();
var config = require('./../config');
var bigpixelsrv = require('./bigpixelsrv');
//游戏应用
//读取用户当前积分
exports.score=function(req,res){
    try{
        var id=req.params.id;   //563da5a335edc86c1571226d
        var userid=req.query.userid;
        var tagsinfo={
            userid:userid
        };
        var url='/api/games/'+id+'/gamescre';

        bigpixelsrv.GetData(url,tagsinfo,function(err,data){
            bigpixelsrv.respondData(res,err,data);
        });
    }
    catch(e){
        bigpixelsrv.handleGeneralError(res,e);
    }
};

//添加积分
exports.savescore=function(req,res){
    try{
        var id=req.params.id;
        var userid=req.body.userid;
        var dots=req.body.dots;
        var tagsinfo={
            userid:userid,
            dots:dots
        };
        var url='/api/games/'+id+'/gamescre';

        bigpixelsrv.PostData(url,tagsinfo, function(error, response, data){
            bigpixelsrv.respondData(res,error,data);
        });
    }catch(e){
        bigpixelsrv.handleGeneralError(res,e);
    }
};

//分页排名
exports.rank=function(req,res){
    try{
        var id=req.params.id;
        var skip=req.query.skip;
        var limit=req.query.limit;
        var  url= '/api/games/'+id+'/rank?skip='+skip+'&limit='+limit;

        bigpixelsrv.GetData(url,function(err,data){
            bigpixelsrv.respondData(res,err,data);
        });
    }catch(e){
        bigpixelsrv.handleGeneralError(res,e);
    }
}

//获取用户当前游戏详细
exports.records=function(req,res){
    try{
        var id=req.params.id;
        var userid=req.query.userid;
        var tagsinfo={
            userid:userid
        };
        var url='/api/games/'+id+'/gamerecord';
        bigpixelsrv.GetData(url,tagsinfo,function(err,data){
            bigpixelsrv.respondData(res,err,data);
        });
    }catch(e){
        bigpixelsrv.handleGeneralError(res,e);
    }
};
